package com.by.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    /**
     * 订单队列
     * @return
     */
    @Bean
    public Queue orderQueue(){
        return new Queue(Constant.ORDER_QUEUE);
    }

    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange(Constant.ORDER_EXCHANGE);
    }

    @Bean
    public Binding orderBinding(Queue orderQueue,DirectExchange orderExchange){
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(Constant.ORDER_ROUTING_KEY);
    }

    @Bean
    public Queue lazyQueue(){
        return new Queue(Constant.LAZY_QUEUE);
    }

    @Bean
    public LazyExchange lazyExchange(){
        return new LazyExchange(Constant.LAZY_EXCHANGE);
    }

    @Bean
    public Binding lazyBingding(Queue lazyQueue,LazyExchange lazyExchange){
        return BindingBuilder.bind(lazyQueue).to(lazyExchange).with(Constant.LAZY_ROUTING_KEY).noargs();
    }
}
